### When Democracy Brings Insecurity
### Hans Lueders
### 1989/90 surveys
### 18 April 2023




# Preparation -------------------------------------------------------------

### packages
library(ggplot2)
library(stargazer)
library(lfe)
library(xtable)
library(readxl)
library(tm)
library(stringr)
library(SnowballC)
library(rgdal)
library(MASS)



### set working directory
path <- "" # define path here
setwd(path)

### empty environment
rm(list=ls())


### load data
load("Data/WhenDemocracyBringsInsecurity_HansLueders_8990surveys.RData")





# Figure 4 ----------------------------------------------------------------

### Regressions
# November 1989
m1 <- felm(stayGDR ~ unemprate_median1993*econproblems + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M010ID, data=d1989nov)
m2 <- felm(voteVK ~ unemprate_median1993*econproblems + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M010ID, data=d1989nov)
m3 <- felm(voteVKSED ~ unemprate_median1993*econproblems + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M010ID, data=d1989nov)
m4 <- felm(future_reformedsocialism ~ unemprate_median1993*econproblems + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M010ID, data=d1989nov)
m5 <- felm(reunification ~ unemprate_median1993*econproblems + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M010ID, data=d1989nov)
m6 <- felm(trustSED ~ unemprate_median1993*econproblems + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M010ID, data=d1989nov)

# February/March 1990
m7 <- felm(stayGDR ~ unemprate_median1993*optimism +  female + as.factor(agegroup) + 
             as.factor(employment) | 0 | 0 | M030ID, data=d1990febmar)
m8 <- felm(voteVK ~ unemprate_median1993*optimism +  female + as.factor(agegroup) + 
             as.factor(employment) | 0 | 0 | M030ID, data=d1990febmar)
m9 <- felm(votePDS ~ unemprate_median1993*optimism +  female + as.factor(agegroup) + 
             as.factor(employment) | 0 | 0 | M030ID, data=d1990febmar)
m10 <- felm(reunification ~ unemprate_median1993*optimism +  female + as.factor(agegroup) + 
              as.factor(employment) | 0 | 0 | M030ID, data=d1990febmar)

# September 1990
m11 <- felm(votePDS ~ unemprate_median1993*econsitOWN + female + as.factor(agegroup) + 
              as.factor(training) + as.factor(employment) | 0 | 0 | M080ID, data=d1990sep)
m12 <- felm(reunification ~ unemprate_median1993*econsitOWN + female + as.factor(agegroup) + 
              as.factor(training) + as.factor(employment) | 0 | 0 | M080ID, data=d1990sep)
m13 <- felm(polinterest ~ unemprate_median1993*econsitOWN + female + as.factor(agegroup) + 
              as.factor(training) + as.factor(employment) | 0 | 0 | M080ID, data=d1990sep)
m14 <- felm(outlook_politicaldevelopment ~ unemprate_median1993*econsitOWN + female + as.factor(agegroup) + 
              as.factor(training) + as.factor(employment) | 0 | 0 | M080ID, data=d1990sep)


### get coefficients
plot2 <- data.frame(matrix(ncol=5, nrow=18))
colnames(plot2) <- c("survey", "variable", "b", "se","include")
plot2$survey <- c(rep(1,6), rep(2,6), rep(3,6))
plot2$survey <- factor(plot2$survey, levels=1:3,
                       labels = c("November 1989\n(econ. problems)", "February/March 1990\n(optimism)", "September 1990\n(own econ. sit.)"))
plot2$variable <- 1:18
plot2$variable <- factor(plot2$variable, levels=1:18,
                         labels = c("Reformed socialism", "Trust in SED", "Vote for SED", "Vote in election", "Reunification", "Stay in GDR",
                                    " ", "  ", "Vote for PDS", " Vote in election", " Reunification", " Stay in GDR",
                                    "   ", "    ", " Vote for PDS", "Political interest", "  Reunification", "Political outlook"))

plot2$include <- c(rep(1,6), rep(0,2), rep(1,4), rep(0,2), rep(1,4))

plot2[1,3:4] <- summary(m4)$coef["unemprate_median1993:econproblems",1:2]
plot2[2,3:4] <- summary(m6)$coef["unemprate_median1993:econproblems",1:2]
plot2[3,3:4] <- summary(m3)$coef["unemprate_median1993:econproblems",1:2]
plot2[4,3:4] <- summary(m2)$coef["unemprate_median1993:econproblems",1:2]
plot2[5,3:4] <- summary(m5)$coef["unemprate_median1993:econproblems",1:2]
plot2[6,3:4] <- summary(m1)$coef["unemprate_median1993:econproblems",1:2]

plot2[7,3:4] <- c(0,0)
plot2[8,3:4] <- c(0,0)
plot2[9,3:4] <- summary(m9)$coef["unemprate_median1993:optimism",1:2]
plot2[10,3:4] <- summary(m8)$coef["unemprate_median1993:optimism",1:2]
plot2[11,3:4] <- summary(m10)$coef["unemprate_median1993:optimism",1:2]
plot2[12,3:4] <- summary(m7)$coef["unemprate_median1993:optimism",1:2]

plot2[13,3:4] <- c(0,0)
plot2[14,3:4] <- c(0,0)
plot2[15,3:4] <- summary(m11)$coef["unemprate_median1993:econsitOWN",1:2]
plot2[16,3:4] <- summary(m13)$coef["unemprate_median1993:econsitOWN",1:2]
plot2[17,3:4] <- summary(m12)$coef["unemprate_median1993:econsitOWN",1:2]
plot2[18,3:4] <- summary(m14)$coef["unemprate_median1993:econsitOWN",1:2]



### Plot
ggplot() + 
  geom_hline(yintercept = 0, lty=2) +
  geom_point(data=plot2, aes(x=variable, y=b, alpha=as.factor(include)), size=2.6) +
  geom_errorbar(data=plot2, aes(x=variable, ymin = b-1.96*se, ymax = b+1.96*se, alpha=as.factor(include)), width=0, size=1.2) + 
  facet_wrap(~survey, scales="free_y") +
  scale_alpha_discrete(range=c(0,1)) +
  xlab("") + 
  ylab("Heterogeneous effect of economic worries\nby high vs. low unemployment rate (1993)") +
  coord_flip() +
  theme_classic() +
  scale_y_continuous(limits = c(-0.3,0.5)) +
  theme(axis.title.x = element_text(size=14, face="bold"),
        axis.title.y = element_blank(),
        axis.text.x = element_text(size=12),
        axis.text.y = element_text(size=12),
        strip.text = element_text(size=14, face="bold"),
        legend.position = "none")




# Table A20 ---------------------------------------------------------------

### Regressions
m1 <- felm(stayGDR ~ unemprate_median1993*econproblems + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M010ID, data=d1989nov)
m2 <- felm(voteVK ~ unemprate_median1993*econproblems + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M010ID, data=d1989nov)
m3 <- felm(voteVKSED ~ unemprate_median1993*econproblems + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M010ID, data=d1989nov)
m4 <- felm(future_reformedsocialism ~ unemprate_median1993*econproblems + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M010ID, data=d1989nov)
m5 <- felm(reunification ~ unemprate_median1993*econproblems + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M010ID, data=d1989nov)
m6 <- felm(trustSED ~ unemprate_median1993*econproblems + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M010ID, data=d1989nov)


### Stargazer output
stargazer(m1,m5,m2,m3,m6,m4,
          omit.stat = c("rsq", "f", "ser"),
          omit=c("AGS", "year"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,
          dep.var.labels  = c("Stay in GDR", "Reunification", "Vote in election", "Vote for SED", "Trust in SED", "Reformed socialism"),
          covariate.labels=c("High unemployment in 1993",
                             "Economic problems",
                             "Female",
                             "Age group: 25-34",
                             "Age group: 35-44",
                             "Age group: 45-54",
                             "Age group: 55-64",
                             "Age group: 65+",
                             "Training: in training",
                             "Training: semi-skilled crafts(wo)man (Teilfacharbeiter)",
                             "Training: skilled crafts(wo)man (Facharbeiter)",
                             "Training: master crafts(wo)man (Meister)",
                             "Training: trade school (Fachschule)",
                             "Training: college (Hochschule)",
                             "Employment: apprentice",
                             "Employment: student",
                             "Employment: worker",
                             "Employment: employee",
                             "Employment: self-employed",
                             "Employment: retired",
                             "Employment: other",
                             "High unemployment in 1993 * Economic problems"),
          digits = 3) 



# Table A21 ---------------------------------------------------------------

### Regressions
m7 <- felm(stayGDR ~ unemprate_median1993*optimism +  female + as.factor(agegroup) + 
             as.factor(employment) | 0 | 0 | M030ID, data=d1990febmar)
m8 <- felm(voteVK ~ unemprate_median1993*optimism +  female + as.factor(agegroup) + 
             as.factor(employment) | 0 | 0 | M030ID, data=d1990febmar)
m9 <- felm(votePDS ~ unemprate_median1993*optimism +  female + as.factor(agegroup) + 
             as.factor(employment) | 0 | 0 | M030ID, data=d1990febmar)
m10 <- felm(reunification ~ unemprate_median1993*optimism +  female + as.factor(agegroup) + 
              as.factor(employment) | 0 | 0 | M030ID, data=d1990febmar)


### Stargazer output
stargazer(m7,m10,m8,m9,
          omit.stat = c("rsq", "f", "ser"),
          omit=c("AGS", "year"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,
          dep.var.labels  = c("Stay in GDR", "Reunification", "Vote in election", "Vote for PDS"),
          covariate.labels=c("High unemployment in 1993",
                             "Optimism about future",
                             "Female",
                             "Age group: 25-34",
                             "Age group: 35-44",
                             "Age group: 45-54",
                             "Age group: 55-64",
                             "Age group: 65+",
                             "Employment: apprentice",
                             "Employment: student",
                             "Employment: worker",
                             "Employment: employee",
                             "Employment: self-employed",
                             "Employment: retired",
                             "Employment: other",
                             "High unemployment in 1993 * Optimism about future"),
          digits = 3) 




# Table A22 ---------------------------------------------------------------

### Regressions
m11 <- felm(votePDS ~ unemprate_median1993*econsitOWN + female + as.factor(agegroup) + 
              as.factor(training) + as.factor(employment) | 0 | 0 | M080ID, data=d1990sep)
m12 <- felm(reunification ~ unemprate_median1993*econsitOWN + female + as.factor(agegroup) + 
              as.factor(training) + as.factor(employment) | 0 | 0 | M080ID, data=d1990sep)
m13 <- felm(polinterest ~ unemprate_median1993*econsitOWN + female + as.factor(agegroup) + 
              as.factor(training) + as.factor(employment) | 0 | 0 | M080ID, data=d1990sep)
m14 <- felm(outlook_politicaldevelopment ~ unemprate_median1993*econsitOWN + female + as.factor(agegroup) + 
              as.factor(training) + as.factor(employment) | 0 | 0 | M080ID, data=d1990sep)


### Stargazer output
stargazer(m14,m12,m13,m11,
          omit.stat = c("rsq", "f", "ser"),
          omit=c("AGS", "year"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,
          dep.var.labels  = c("Political outlook", "Reunification", "Political interest", "Vote for PDS"),
          covariate.labels=c("High unemployment in 1993",
                             "Own economic situation",
                             "Female",
                             "Age group: 25-34",
                             "Age group: 35-44",
                             "Age group: 45-54",
                             "Age group: 55-64",
                             "Age group: 65+",
                             "Training: in training",
                             "Training: semi-skilled crafts(wo)man (Teilfacharbeiter)",
                             "Training: skilled crafts(wo)man (Facharbeiter)",
                             "Training: master crafts(wo)man (Meister)",
                             "Training: trade school (Fachschule)",
                             "Training: college (Hochschule)",
                             "Employment: apprentice",
                             "Employment: student",
                             "Employment: worker",
                             "Employment: employee",
                             "Employment: self-employed",
                             "Employment: retired",
                             "Employment: other",
                             "High unemployment in 1993 * Own economic situation"),
          digits = 3) 




# Table A23 ---------------------------------------------------------------

### Regressions
m1 <- felm(econproblems ~ unemprate_median1993 + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M010ID, data=d1989nov)

m2 <- felm(optimism ~ unemprate_median1993 +  female + as.factor(agegroup) + 
             as.factor(employment) | 0 | 0 | M030ID, data=d1990febmar)

m3 <- felm(econsitGDR ~ unemprate_median1993 + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M080ID, data=d1990sep)
m4 <- felm(econsitOWN ~ unemprate_median1993 + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M080ID, data=d1990sep)
m5 <- felm(outlook_personaldevelopment ~ unemprate_median1993 + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M080ID, data=d1990sep)
m6 <- felm(outlook_jobsituation ~ unemprate_median1993 + female + as.factor(agegroup) + 
             as.factor(training) + as.factor(employment) | 0 | 0 | M080ID, data=d1990sep)


### Stargazer output
stargazer(m1,m2,m3,m4,m5,m6,
          omit.stat = c("rsq", "f", "ser"),
          omit=c("AGS", "year"),
          df = F,
          notes.align="c",
          no.space=T,
          font.size="tiny",
          model.names=F,
          dep.var.labels.include = T,
          dep.var.labels  = c("Econ. problems", "Optimism", "GDR econ. sit.", "Own econ. sit.", "Outlook: personal", "Outlook: jobs"),
          column.labels = c("(Nov 1989)", "(Feb/Mar 1990)", "(Sep 1990)", "(Sep 1990)", "(Sep 1990)", "(Sep 1990)"),          
          covariate.labels=c("High unemployment in 1993",
                             "Female",
                             "Age group: 25-34",
                             "Age group: 35-44",
                             "Age group: 45-54",
                             "Age group: 55-64",
                             "Age group: 65+",
                             "Training: in training",
                             "Training: semi-skilled crafts(wo)man (Teilfacharbeiter)",
                             "Training: skilled crafts(wo)man (Facharbeiter)",
                             "Training: master crafts(wo)man (Meister)",
                             "Training: trade school (Fachschule)",
                             "Training: college (Hochschule)",
                             "Employment: apprentice",
                             "Employment: student",
                             "Employment: worker",
                             "Employment: employee",
                             "Employment: self-employed",
                             "Employment: retired",
                             "Employment: other"),
          digits = 3) 









